<html>
<head><meta charset="utf-8"><title>How to set longcall on a specific function? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html">How to set longcall on a specific function?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213862262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/213862262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#213862262">(Oct 20 2020 at 00:10)</a>:</h4>
<p>So I want to enable longcalls but only on extern functions that I'm linking against. For instance this issue: <a href="https://github.com/rust-lang/rust/issues/65403">https://github.com/rust-lang/rust/issues/65403</a> enables long calls for the entire generated binary, including functions that I write. I tried doing something like #[target_feature(enable = "longcall")] on a function def like extern "C" fn example_func(arg: usize) -&gt; usize; to no avail (just says longcall isn't available even though the compiler option in the issue above works to set long calls for everything). Is there a way to enable long calls like in C where I can do #pragma longcall(1) and/or __attribute__((longcall)) ?</p>



<a name="213918559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/213918559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#213918559">(Oct 20 2020 at 13:29)</a>:</h4>
<p>I've got two ideas for a solution. The first is just a macro that effectively converts a regular call to a long call with some magic code. The second is a compiler plugin do a syntax extension that will make these function calls long calls, I think compiler plugins might also be able to do llvm stuff so maybe I could add a longcall attribute to the function there?<br>
Any thoughts on those?</p>



<a name="213961661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/213961661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#213961661">(Oct 20 2020 at 18:36)</a>:</h4>
<p>Third idea is a small C shim that just does inline assembly to jump to the target address</p>



<a name="214038240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214038240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214038240">(Oct 21 2020 at 11:39)</a>:</h4>
<p>does llvm support the longcall convention ?</p>



<a name="214038590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214038590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214038590">(Oct 21 2020 at 11:43)</a>:</h4>
<p>also, which targets do you want to use <code>long_call</code> ? ARM or MIPS?<br>
For those who don't know about this calling convention, just like me:</p>
<ul>
<li><a href="https://clang.llvm.org/docs/AttributeReference.html#long-call-far">https://clang.llvm.org/docs/AttributeReference.html#long-call-far</a></li>
<li><a href="https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/ARM-Function-Attributes.html#ARM-Function-Attributes">https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/ARM-Function-Attributes.html#ARM-Function-Attributes</a></li>
<li><a href="https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/MIPS-Function-Attributes.html#MIPS-Function-Attributes">https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/MIPS-Function-Attributes.html#MIPS-Function-Attributes</a></li>
</ul>



<a name="214131008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214131008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214131008">(Oct 22 2020 at 00:21)</a>:</h4>
<p>I was targeting PPC, working on embedded development. Clang supports long calls and I can use <code>-Ctarget-features=+longcall</code> in my <code>.cargo/config</code> with build flags and every single call becomes long call, which leads me to think llvm supports longcall</p>



<a name="214131104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214131104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214131104">(Oct 22 2020 at 00:23)</a>:</h4>
<p>The ideal solution here is just an attribute I can stick on functions and it just works</p>



<a name="214267341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214267341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214267341">(Oct 23 2020 at 02:09)</a>:</h4>
<p>Does anyone have a resource for writing compiler plugins to modify the llvm bitcode? I can't seem to find any</p>



<a name="214340154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214340154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214340154">(Oct 23 2020 at 17:13)</a>:</h4>
<p><a href="https://osblog.stephenmarz.com/ch7.html">https://osblog.stephenmarz.com/ch7.html</a></p>



<a name="214368678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214368678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214368678">(Oct 23 2020 at 21:33)</a>:</h4>
<p>Interesting resource, but it doesn't seem like what I'm looking for</p>



<a name="214368996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214368996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214368996">(Oct 23 2020 at 21:37)</a>:</h4>
<p>which references have you collected so far?</p>



<a name="214409138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20set%20longcall%20on%20a%20specific%20function%3F/near/214409138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20set.20longcall.20on.20a.20specific.20function.3F.html#214409138">(Oct 24 2020 at 04:43)</a>:</h4>
<p>For this specific problem, the issue in the first message in this topic, <a href="https://doc.rust-lang.org/reference/attributes/codegen.html">https://doc.rust-lang.org/reference/attributes/codegen.html</a>, <a href="https://doc.rust-lang.org/reference/attributes.html">https://doc.rust-lang.org/reference/attributes.html</a>. I've got a couple others related to macros when I was trying to do the macro stuff to pretend its a longcall</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>